import { defineStore } from 'pinia';


export const useEquipmentInfo = defineStore({
  id: 'EquipmentInfo',

  state: () => ({
    areaInfo: [] as Record<string, any>[],
    targetInfo: [] as Record<string, any>[],
  }),

  actions: {
    getData() {
      return {
        areaInfo: this.areaInfo,
        targetInfo: this.targetInfo,
      };
    },
    addInfo(type: string, value: Record<string, any>) {
      const addInfoMap = {
        area: () => { this.areaInfo.push(value); },
        target: () => { this.targetInfo.push(value); },
      };

      addInfoMap[type]();
    },
    removeData(type: string, id: string | number) {
      const removeInfoMap = {
        area: () => { this.areaInfo = this.areaInfo.filter((item) => item.id !== id); },
        target: () => { this.targetInfo = this.targetInfo.filter((item) => item.id !== id); },
      };

      removeInfoMap[type]();
    },
  },

  persist: true,
});
